<template>
    <div class="alarmConfiguration zy-content ">
        <div class="search-box-layout">
          <Row :gutter="24">
            <Col span="4">
              <div>
                <p class="label">{{$t('spareParts.company')}}</p>
                <div class="ipt">
                    <Select v-model="searchParams.companyId" filterable clearable
                            :placeholder="`${$t('common.selectInfo')}`" @on-change="getBackupList($event)">
                        <Option v-for="(item) of companyList" :value="item.id" :key="item.code"
                                :label="item.fullName">
                        </Option>
                    </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.Warehouse')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.backupConfigId" filterable clearable
                          :placeholder="`${$t('common.selectInfo')}`" @on-change="getShelfList($event)"
                          @on-open-change="openBackupSelect">
                    <Option v-for="(item) of backupList" :value="item.id" :key="item.id"
                            :label="item.backupName">
                    </Option>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.Rack')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.shelfConfigId" filterable clearable
                          :placeholder="`${$t('common.selectInfo')}`" @on-change="getLocationList($event)"
                          @on-open-change="openShelfSelect">
                    <Option v-for="(item) of shelfList" :value="item.id" :key="item.id" :label="item.shelf">
                    </Option>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.Location')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.locationConfigId" filterable clearable
                          :placeholder="`${$t('common.selectInfo')}`"
                          @on-open-change="openLocationSelect">
                    <Option v-for="(item) of locationList" :value="item.id" :key="item.id"
                            :label="item.location">
                    </Option>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.PartNo')}}</p>
                <div class="ipt">
                  <Input type="text" v-model="searchParams.materielNo" clearable
                         :placeholder="`${$t('common.inputInfo')}`" :maxlength="32"></Input>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.SpareNumber')}}</p>
                <div class="ipt">
                  <Input type="text" v-model="searchParams.backupNo" clearable
                         :placeholder="`${$t('common.inputInfo')}`" :maxlength="32"></Input>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.GoodsName')}}</p>
                <div class="ipt">
                  <Input type="text" v-model="searchParams.goodsName" clearable
                         :placeholder="`${$t('common.inputInfo')}`" :maxlength="32"></Input>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.Specification')}}</p>
                <div class="ipt">
                  <Input type="text" v-model="searchParams.specification" clearable
                         :placeholder="`${$t('common.inputInfo')}`" :maxlength="32"></Input>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('common.SpareClassification')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.sparePartsVal" filterable clearable
                          :placeholder="`${$t('common.selectInfo')}`" @on-change="handleChange">
                    <Option v-for="(item) of sparePartsList" :value="item.label" :key="item.label"
                            :label="item.value"></Option>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('spareParts.AssetType')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.assetType" filterable clearable
                          :placeholder="`${$t('common.selectInfo')}`">
                    <Option v-for="(item) of assetType" :value="item.label" :key="item.label"
                            :label="item.value"></Option>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('spareParts.ObjectClassification')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.goodsType"
                          filterable
                          clearable
                          :placeholder="`${$t('common.selectInfo')}`">
                    <Option v-for="(item) of goodsType"
                            :value="item.value"
                            :key="item.value"
                            :label="item.value"/>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="4">
              <div>
                <p class="label">{{$t('spareParts.ControlMode')}}</p>
                <div class="ipt">
                  <Select v-model="searchParams.manageType" filterable clearable
                          :placeholder="`${$t('common.selectInfo')}`">
                    <Option v-for="(item) of manageType" :value="item.label" :key="item.label"
                            :label="item.value">
                    </Option>
                  </Select>
                </div>
              </div>
            </Col>
            <Col span="24">
              <div class="t-c">
                <div class="ipt">
                  <Button class="search-btn" type="primary" v-if="checkBtnPermission.standingBookList" @click="changeNum()">
                    {{ $t('common.Query') }}
                  </Button>
                  <Button
                      class="reset-btn"
                      @click="reset()"
                      v-has="'standingBookList'"
                  >{{ $t('common.reset') }}
                  </Button>
                </div>
              </div>
            </Col>
          </Row>
        </div>
        <div class="list-layout mt16">
          <div class="btns clear">
            <span class="title">{{ $t('common.listInformation') }}</span>

            <Button  @click="delFaultCodeShowClick" v-if="checkBtnPermission.standingBookDelete">{{ $t('common.batchDelete') }}</Button>
            <Button  @click="exportTemplateClick" v-if="checkBtnPermission.standingBookExport">{{ $t('common.batchExport') }}</Button>
            <Button  @click="importExcelShow" v-if="checkBtnPermission.standingBookImport">{{ $t('common.Import') }}</Button>
            <Button  @click="exportTemplate" v-if="checkBtnPermission.standingBookTemplate">{{ $t('common.Download') }}</Button>
            <Button @click="printShowClick" v-has="'standingBookPrint'">{{$t('选择打印')}}</Button>
              <Button @click="getTableColumns(columns)">
                  {{ handleContextMenuStatus ? $t('显示操作栏') : $t('隐藏操作栏') }}
              </Button>
          </div>
          <div class="tableContent">
            <Table  class="resizable-table" border @on-column-width-resize="onColumnWidthResize"
                    :columns="columnsList" ellipsis ref="selection" stripe  :data="dataArr"
                   @on-selection-change="onSelectChange">
              <template slot-scope="{ row ,index}" slot="action">
                    <span class="operationBtn" @click="createfaultCodeShowH(row,true)"
                          v-if="checkBtnPermission.standingBookUpdate"><i class="iconfont zy-common-bianji"></i>{{ $t('common.Edit') }}</span>
                <span class="operationBtn" @click="createfaultCodeShowH(row,false)"
                      v-has="'standingBookCheck'"><i class="iconfont zy-common-chakan"></i>{{ $t('common.Check') }}</span>
                <Dropdown transfer-class-name="theme-dropdown" :transfer="true" placement="left-start">
                  <a href="javascript:void(0)">
                    <i class="iconfont zy-common-gengduo1"></i>{{ $t('common.more') }}
                    <Icon type="arrow-down-b"></Icon>
                  </a>
                  <Dropdown-menu slot="list">
                    <Dropdown-item @click.native="delPrrShowH(row)" v-if="checkBtnPermission.standingBookDelete">
                      <span class="operationBtn" >{{ $t('common.Delete') }}
                                </span>
                    </Dropdown-item>
                    <Dropdown-item @click.native="handlePrint(row)">
                      <span  v-has="'standingBookPrint'" class="operationBtn" >{{ $t('打印') }}
                                </span>
                    </Dropdown-item>
                  </Dropdown-menu>
                </Dropdown>
              </template>
            </Table>
          </div>
          <div class="pageWrap mt16">
            <pageLeftTitle :total="total" :selected="delIds.length" />
            <Page :total="total" :page-size="pageSize" :page-size-opts="pageSizeOption" :current="pageNum"
                  @on-change="changePageNum" @on-page-size-change="changePageSize" show-sizer show-total/>
          </div>
        </div>
        <Modal :mask-closable="false" class="modal-content-layout" v-model="create" :title="addtitle" width="800px">
            <Form ref="form" class="formList" :model="formItem" :rules="ruleValidate" label-position="top">
                <Row :gutter="20">
                    <Col span="12">
                        <FormItem :label="$t('spareParts.Warehouse')"><!-- 仓库 -->
                            <Input type="text" v-model="formItem.warehouseName" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem :label="$t('spareParts.Rack')"><!-- 货架： -->
                            <Input type="text" v-model="formItem.shelfConfigName" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row :gutter="20">
                    <Col span="12">
                        <FormItem :label="$t('spareParts.Location')"><!-- 库位： -->
                            <Input type="text" v-model="formItem.locationConfigName" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem :label="$t('spareParts.PartNo')" prop="remark"><!-- 料号： -->
                            <Input type="text" v-model="formItem.materielNo" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                </Row>
              <Row :gutter="20">
                    <Col span="12">
                        <FormItem :label="$t('common.SpareNumber')" prop="remark"><!-- 备件编号： -->
                            <Input type="text" v-model="formItem.backupNo" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem :label="$t('common.GoodsName')" prop="remark"><!-- 品名： -->
                            <Input type="text" v-model="formItem.goodsName" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                </Row>
              <Row :gutter="20">
                    <Col span="12">
                        <FormItem :label="$t('common.Specification')" prop="remark"><!-- 规格： -->
                            <Input type="text" v-model="formItem.specification" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem :label="$t('spareParts.Brand')" prop="remark"><!-- 品牌： -->
                            <Input type="text" v-model="formItem.brand" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                </Row>
              <Row :gutter="20">
                    <Col span="12">
                        <FormItem :label="$t('common.SpareClassification')"><!-- 备件分类： -->
                            <Input type="text" v-model="spareParts" disabled :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem :label="$t('spareParts.ControlMode')"><!-- 管理方式： -->
                            <Input type="text" v-model="formItem.manageTypeStr" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                </Row>
              <Row :gutter="20">
                    <Col span="12">
                        <FormItem :label="$t('spareParts.quantity')"><!-- 数量： -->
                            <Input type="text" v-model="formItem.quantityInStock"
                                   :placeholder="`${$t('common.inputInfo')}`" :autosize="{minRows: 2,maxRows: 5}"
                                   :disabled="!isShow"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem :label="$t('common.WarehouseManager')"><!-- 仓库管理员： -->
                            <Input type="text" v-model="formItem.manageBy" disabled
                                   :placeholder="`${$t('common.inputInfo')}`"
                                   :autosize="{minRows: 2,maxRows: 5}"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <template v-if="formItem.assetType !== 2">
                  <Row :gutter="20">
                        <Col span="12">
                            <FormItem :label="$t('ledger.AssetDetails')"><!-- 资产详情： -->
                                <Input type="text" v-model="formItem.assetDetails" disabled
                                       :placeholder="`${$t('common.inputInfo')}`"
                                       :autosize="{minRows: 2,maxRows: 5}"></Input>
                            </FormItem>
                        </Col>
                        <Col span="12">
                            <FormItem :label="$t('ledger.AssetNo')"><!-- 资产编号： -->
                                <Input type="text" v-model="formItem.assetsNo"
                                       :placeholder="`${$t('common.inputInfo')}`"
                                       :autosize="{minRows: 2,maxRows: 5}"></Input>
                            </FormItem>
                        </Col>
                    </Row>
                  <Row :gutter="20">
                        <Col span="12">
                            <FormItem :label="$t('ledger.OriginalValue')"><!-- 资产原值： -->
                                <Input type="text" v-model="formItem.assetsOriginal"
                                       @on-change="getassetsData"
                                       :placeholder="`${$t('common.inputInfo')}`"
                                       :autosize="{minRows: 2,maxRows: 5}"></Input>
                            </FormItem>
                        </Col>
                        <Col span="12">
                            <FormItem :label="$t('equipmentscrapped.ResidualValue')"><!-- 资产残值： -->
                                <Input type="text" v-model="formItem.assets" disabled
                                       :placeholder="`${$t('common.inputInfo')}`"
                                       :autosize="{minRows: 2,maxRows: 5}"></Input>
                            </FormItem>
                        </Col>
                    </Row>
                </template>
            </Form>
            <div slot="footer" v-show="isShow">
                <Button  type="default" @click="create = false">{{ $t('common.Cancle') }}</Button>
                <Button  type="primary" :loading="loading" @click="addOk('form')">{{ $t('maintenance.Confirmed') }}
                </Button>
            </div>
        </Modal>
        <Modal :mask-closable="false"  class="modal-title-layout" v-model="delFaultCodeShowF" :title="$t('common.Delete')">
          <div class="icon red">
            <i class="iconfont zy-common-shanchu"></i>
          </div>
          <p class="title">
            <span>{{ $t('common.sureDelete') }}</span>
          </p>
            <div slot="footer">
                <Button type="default" @click="delFaultCodeShowF = false">{{ $t('common.Cancle') }}</Button>
                <Button type="primary" :loading="loading" @click="deleteOk">{{ $t('maintenance.Confirmed') }}</Button>
            </div>
        </Modal>
        <importExcelModal :importExcelStateF="importExcelState" v-if="importExcelState"
                          @importExcelChange="importExcelChange"></importExcelModal>
      <ledgerPrintModal ref="ledgerPrintModal"/>
    </div>
</template>

<script>
import {searchApi, addApi, editApi, deleteApi, templateApi, exportApi} from "@/api/spareParts/account.js";
import {getUserSelect, getCompany, getBackup, getShelf, getLocation} from "@/api/index.js";
import importExcelModal from '@/components/importExcel.vue';
import fileDownload from 'js-file-download';
import util from "@/util/util";
import ledgerPrintModal from './component/ledgerPrintModal'
import toggleTableOperation from "@/mixins/toggleTableOperation";
export default {
    name: "goodsShelves",//库位配置
    components: {importExcelModal,ledgerPrintModal},
    mixins:[toggleTableOperation],
    data() {
        return {
            tarGetDay:'',
            timeID:null,
            companyList: [],
            backupList: [],
            shelfList: [],
            locationList: [],
            printArr:[],
            spareParts: "",
            importExcelState: false, /*批量导入*/
            formItem: {
                backupConfigId: null,
                backupShelfConfigId: null,
                scrapStatus: null
            },
            addtitle: "",
            allCheck: false,
            loading: false,
            create: false,
            searchParams: {},
            pageNum: 1,
            pageSize: 10,
            total: 0,
            dataArr: [],
            delFaultCodeShowF: false,//是否显示删除弹窗
            pageSizeOption: [10, 20, 30, 40],
            delIds: [],
            selection: [],
            checkBtnPermission: {},
            createByOptions: [],
            backupId: '',
            shelfId: '',
            isShow: false,
            sparePartsAbcList: [{
                label: 'A',
                value: 'A类'
            }, {
                label: 'B',
                value: 'B类'
            }, {
                label: 'C',
                value: 'C类'
            },
            ],
            sparePartsList: [{
                label: 'AV',
                value: 'AV类'
            }, {
                label: 'AE',
                value: 'AE类'
            }, {
                label: 'AD',
                value: 'AD类'
            },
                {
                    label: 'BV',
                    value: 'BV类'
                }, {
                    label: 'BE',
                    value: 'BE类'
                }, {
                    label: 'BD',
                    value: 'BD类'
                },
                {
                    label: 'CV',
                    value: 'CV类'
                }, {
                    label: 'CE',
                    value: 'CE类'
                }, {
                    label: 'CD',
                    value: 'CD类'
                },
            ],
            sparePartsVedList: [{
                label: 'V',
                value: 'V类'
            }, {
                label: 'E',
                value: 'E类'
            }, {
                label: 'D',
                value: 'D类'
            },
            ],
            goodsType: [],
            assetType: [{
                label: '1',
                value: '资产类'
            }, {
                label: '2',
                value: '非资产类'
            },

            ],
            timerId: null,
            manageType: [{
                label: 1,
                value: '单个管理'
            },
                {
                    label: 2,
                    value: '批量管理'
                },
            ],
            types: [{id: 0, value: '否'}, {id: 1, value: '是'}],
            columns: [
                {
                    key: 'selection',
                    type: 'selection',
                    width: 60,
                    align: 'center',
                },
                {
                    title: `${this.$t('spareParts.company')}`,
                    key: 'companyName',
                    minWidth: 150,
                    align: 'center',
                    type: 'select',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.Warehouse')}`,
                    key: 'warehouseName',
                    minWidth: 120,
                    align: 'center',
                    type: 'select',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.Rack')}`,
                    key: 'shelfConfigName',
                    minWidth: 100,
                    align: 'center',
                    type: 'select',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.Location')}`,
                    key: 'locationConfigName',
                    minWidth: 100,
                    align: 'center',
                    type: 'select',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.PartNo')}`,
                    key: 'materielNo',
                    minWidth: 100,
                    align: 'center',
                    type: 'input',
                    resizable: true
                },
                {
                    title: `${this.$t('common.SpareNumber')}`,
                    key: 'backupNo',
                    minWidth: 160,
                    align: 'center',
                    type: 'input',
                    resizable: true
                },
                {
                    title: `${this.$t('common.GoodsName')}`,
                    key: 'goodsName',
                    minWidth: 160,
                    align: 'center',
                    type: 'input',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.Specification')}`,
                    key: 'specification',
                    minWidth: 120,
                    align: 'center',
                    type: 'input',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.Brand')}`,
                    key: 'brand',
                    minWidth: 100,
                    align: 'center',
                    type: 'input',
                    resizable: true
                },
                {
                    title: `${this.$t('common.SpareClassification')}`,
                    key: 'location',
                    minWidth: 160,
                    align: 'center',
                    type: 'select',
                    render: (h, params) => {
                        return h('div', params.row.sparePartsABC + params.row.sparePartsVED)
                    },
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.Classification')}`,
                    key: 'goodsTypeStr',
                    minWidth: 140,
                    align: 'center',
                    type: 'select',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.AssetType')}`,
                    key: 'assetTypeStr',
                    minWidth: 120,
                    align: 'center',
                    type: 'select',
                    resizable: true
                    // render: (h, params) => {
                    //         return h('div',params.row.assetType === "1" ? '资产类' : params.row.assetType === "2" ? '非资产类' : '')
                    //     }
                },
                {
                    title: `${this.$t('common.ControlMode')}`,
                    key: 'manageTypeStr',
                    minWidth: 120,
                    align: 'center',
                    type: 'select',
                    resizable: true
                    //  render: (h, params) => {
                    //         return h('div',params.row.assetType === 1 ? '单个管理' : params.row.assetType === 2 ? '批量管理' : '')
                    //     }
                },
                {
                    title: `${this.$t('spareParts.quantity')}`,
                    key: 'quantityInStock',
                    minWidth: 100,
                    align: 'center',
                    type: 'input',
                    resizable: true

                },
                {
                    // title: '安全系数Z',
                    title: `${this.$t('安全系数Z')}`,
                    key: 'safetyCoefficient',
                    minWidth: 140,
                    align: 'center',
                    resizable: true
                },
                {
                    // title: '采购提前期L(天)',
                    title: `${this.$t('采购提前期L(天)')}`,
                    key: 'purchaseLeadDay',
                    minWidth: 140,
                    align: 'center',
                    resizable: true
                },
                {
                    // title: '安全库存',
                    title: `${this.$t('spareParts.SafetyStock')}`,
                    key: 'safeStock',
                    minWidth: 140,
                    align: 'center',
                    resizable: true
                },
                {
                    title: `${this.$t('spareParts.warehouseManager')}`,
                    key: 'manageBy',
                    minWidth: 180,
                    align: 'center',
                    type: 'input',
                    resizable: true
                    // render: (h, params) => {
                    //     return h('div', params.row.ydlx == 1 ? '转售'  : params.row.ydlx == 3 ? '租用' : params.row.ydlx == 4 ? '借用' : params.row.ydlx == 5 ? '仅记录' : params.row.ydlx == 6 ? '委外生产借用' : '')
                    // }
                },
                //  {
                //     title: '是否为报废库位',
                //     key: 'scrapStatus',
                //     minWidth: 100,
                //     align: 'center',
                //     render: (h, params) => {
                //         return h('div', params.row.scrapStatus === 0 ? '否' : params.row.scrapStatus === 1 ? '是' : '')
                //     }
                // },
                {
                    title: `${this.$t('common.operation')}`,
                    slot: "action",
                    fixed: 'right',
                    minWidth: this.util.autoWidth(250,280),
                    align: "center"
                }
            ],
            ruleValidate: {
                companyId: [
                    {required: true, message: '请选择公司', trigger: 'blur'}
                ],
                backupConfigId: [
                    {required: true, message: '请选择仓库', trigger: 'blur', type: "number"}
                ],
                backupShelfConfigId: [
                    {required: true, message: '请选择货架', trigger: 'blur', type: "number"}
                ],
                shelf: [
                    {required: true, message: '请填写库位', trigger: 'blur',}
                ],
                scrapStatus: [
                    {required: true, message: '请选择货架', trigger: 'blur', type: "number"}
                ],
            }
        }
    },
    mounted() {

        this.getTableColumnsWidth(this.columns)

        this.getList()
        this.searchList();
        this.getCompanyList();
        this.getUserList();
        let itemList = JSON.parse(window.localStorage.getItem('USER_URI'))
        for (let item of itemList) {
            if (item.code == "standingBookList") {
                this.checkBtnPermission.standingBookList = true
            }
            // if (item.code == "storeHouseAdd") {
            //     this.checkBtnPermission.storeHouseAdd = true
            // }
            if (item.code == "standingBookDelete") {
                this.checkBtnPermission.standingBookDelete = true
            }
            if (item.code == "standingBookUpdate") {
                this.checkBtnPermission.standingBookUpdate = true
            }
            if (item.code == "standingBookExport") {
                this.checkBtnPermission.standingBookExport = true
            }
            if (item.code == "standingBookImport") {
                this.checkBtnPermission.standingBookImport = true
            }
            if (item.code == "standingBookTemplate") {
                this.checkBtnPermission.standingBookTemplate = true
            }
        }

    },
    watch: {
        'searchParams.companyId': {
            handler(val, oldVal) {
                this.$set(this.searchParams, 'backupConfigId', null)
                this.$set(this.searchParams, 'shelfConfigId', null)
                this.$set(this.searchParams, 'locationConfigId', null)
                this.backupList = []
                this.shelfList = []
                this.locationList = []
            },
            deep: false
        },
        'searchParams.backupConfigId': {
            handler(val, oldVal) {
                this.$set(this.searchParams, 'shelfConfigId', null)
                this.$set(this.searchParams, 'locationConfigId', null)
                this.shelfList = []
                this.locationList = []
            },
            deep: false
        },
        'searchParams.shelfConfigId': {
            handler(val, oldVal) {
                this.$set(this.searchParams, 'locationConfigId', null)
                this.locationList = []
            },
            deep: false
        },

    },
    methods: {
      getList(){
        this.axios({
          method: 'post',
          url: '/dms/dict/list ',
          data:{
            pageNo: 1,
            pageSize: 100
          }
        }).then(res => {
          if(res.code === 200){
            if (res.data.list && res.data.list.length){
              this.goodsType = res.data.list.filter(val=>val.name === '备件分类')
            }
          }else{
            this.$Message.warning(({content:res.msg,duration:6,closable:true}));
          }
        })
      },
      handlePrint(record) {
        let arr = []
        arr.push(record)
        this.$refs.ledgerPrintModal.show(arr,1)
      },
      //批量打印
      printShowClick() {
            if (this.printArr.length == 0) {
                return;
            } else {
                this.$refs.ledgerPrintModal.show(this.printArr,1)
            }
        },
      debounceSerach(fn, delay){
        let _this = this
        return function f(...args) {
          if (_this.timeID) {
            clearTimeout(_this.timeID);
          }
          _this.timeID = setTimeout(() => {
            fn(args);
          }, delay);
        };
      },
        //计算资产残值
        getassetsData() {
          if (!this.formItem.assetsOriginal){
              return
           }
        const fn = this.debounceSerach(()=>{
          const params = {
            days: this.tarGetDay,
            original: this.formItem.assetsOriginal,
            depreciation: this.formItem.depreciation
          }
          // if (!this.formItem.useTime) {
          //   params.days = 0
          // }
          this.axios({
            method: 'get',
            url: '/dms/backup/scrapApply/calculationAsset',
            params
          }).then(res => {
            if (res.code === 200) {
              if (res.data) {
                this.$set(this.formItem, 'assets', res.data)
              }
            } else {
              this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
            }
          })
        },300)
         fn()
        },
        //获取公司
        getCompanyList() {
            getCompany().then(res => {
                if (res.code === 200) {
                    this.companyList = res.data
                } else {
                    this.companyList = []
                    this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                }
            }).finally(() => {
                this.loading = false
            })
        },
        //获取仓库
        getBackupList(data) {
            let params = {
                companyId: data
            }
            getBackup(params).then(res => {
                if (res.code === 200) {
                    this.backupList = res.data
                }
                // else {
                //     this.$Message.warning(({ content: res.msg, duration: 6, closable: true }));
                // }
            }).finally(() => {
                this.loading = false
            })
        },

        openBackupSelect(isOpen) {
            if (isOpen === true) {
                if (!this.searchParams.companyId) {
                    this.$Message.warning(({content: "请先选择公司", duration: 6, closable: true}));
                    return false;
                }
            }
        },
        //获取货架下拉列表
        getShelfList(data) {
            let params = {}
            params.delIds = []
            params.delIds.push(data)
            getShelf(params).then(res => {
                if (res.code === 200) {
                    this.shelfList = res.data
                } else {
                    this.shelfList = []
                    //  this.$Message.warning(({ content: res.msg, duration: 6, closable: true }));
                }
            }).finally(() => {
                this.loading = false
            })
        },
        openShelfSelect(isOpen) {
            if (isOpen === true) {
                if (!this.searchParams.backupConfigId) {
                    this.$Message.warning(({content: "请先选择仓库", duration: 6, closable: true}));
                    return false;
                }
            }
        },

        //获取库位下拉列表
        getLocationList(data) {
            let params = {}
            params.delIds = []
            params.delIds.push(data)
            getLocation(params).then(res => {
                if (res.code === 200) {
                    this.locationList = res.data
                } else {
                    this.locationList = []
                    // this.$Message.warning(({ content: res.msg, duration: 6, closable: true }));
                }
            }).finally(() => {
                this.loading = false
            })
        },
        openLocationSelect(isOpen) {
            if (isOpen === true) {
                if (!this.searchParams.shelfConfigId) {
                    this.$Message.warning(({content: "请先选择货架", duration: 6, closable: true}));
                    return false;
                }
            }
        },
        //获取管理员
        getUserList() {
            getUserSelect().then(res => {
                if (res.code === 200) {
                    this.createByOptions = res.data.map(item => {
                        return {
                            ...item,
                            showName: item.empno + '----' + item.username
                        }
                    })
                } else {
                    this.createByOptions = []
                    this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                }
            }).finally(() => {
                this.loading = false
            })
        },
      reset(){
        this.searchParams = {};
        this.changeNum();
      },
        //分页
        changeNum() {
            this.pageNum = 1;
            this.searchList();
        },
        changePageSize(pageSize) {
            this.pageSize = pageSize;
            this.searchList();
        },
        changePageNum(val) {
            this.pageNum = val;
            this.searchList();
        },
        handleChange(val) {
            if (val) {
                this.searchParams.sparePartsABC = val[0]
                this.searchParams.sparePartsVED = val[1]
            } else {
                this.searchParams.sparePartsABC = ""
                this.searchParams.sparePartsVED = ""
            }

        },
        //查询列表
        searchList() {
            let params = {
                pageNum: this.pageNum,
                pageSize: this.pageSize,
            };


            for (let key in this.searchParams) {
                if (this.searchParams[key]) {
                    this.$set(params, key, this.searchParams[key])
                }
            }

            searchApi(params).then(res => {
                
                if (res.code === 200) {
                    this.dataArr = res.data.list
                    this.total = res.data.total
                } else {
                    this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                }
            })
        },
        //增加或编辑
        createfaultCodeShowH(row, edit) {
            this.isShow = edit
            this.$refs.form.resetFields();
            if (edit) {
                this.addtitle = `${this.$t('common.Edit')}`
            } else {
                //this.addtitle = "查看"
                this.addtitle = `${this.$t('common.Check')}`
            }
            if (row.id) {
                this.formItem = JSON.parse(JSON.stringify(row))
                this.spareParts = this.formItem.sparePartsABC + this.formItem.sparePartsVED
                // this.formItem = {
                //     id: row.id,
                //     warehouseName: row.warehouseName,
                //     shelfConfigName: row.shelfConfigName,
                //     locationConfigName: row.locationConfigName,
                //     materielNo:row.materielNo,
                //     backupNo:row.backupNo,
                //     goodsName: row.goodsName,
                //     specification:  row.specification,
                //     brand:  row.brand,
                //     sparePartsABC:  row.sparePartsABC,
                //     manageType:  row.manageType,
                //     managmaterielNoeBy:  row.manageBy,
                // };
              this.axios({
                method: 'get',
                url: '/dms/backup/scrapApply/getBackupUseDays',
                params: {
                  backupId:row.id
                }
              }).then(res => {
                if (res.code === 200) {
                  this.tarGetDay = res.data
                  if (this.formItem.assetsOriginal){
                    this.getassetsData()
                  }
                  this.create = true;
                } else {
                  this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                }
              })
            } else {
                this.formItem = {};
              this.create = true;
            }
        },
        addOk(name) {
            this.$refs[name].validate((valid) => {
                if (!valid) {
                    return
                } else {
                    this.loading = true;
                    if (this.formItem.id) {
                        let params = {
                            id: this.formItem.id,
                            assetsOriginal: this.formItem.assetsOriginal,
                            quantityInStock: this.formItem.quantityInStock,
                            assetsNo: this.formItem.assetsNo,
                            pageNum: 1,
                            pageSize: 20
                        }
                        editApi(params).then(res => {
                            this.loading = false;
                            if (res.code === 200) {
                                this.changeNum();
                                this.$Message.success("编辑成功");
                                this.create = false;
                            } else {
                                this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                            }
                        })
                    }
                    // else {
                    //     addApi(this.formItem).then(res => {
                    //         this.loading = false;
                    //         if (res.code === 200) {
                    //             this.changeNum();
                    //             this.$Message.success("新增成功");
                    //             this.create = false;
                    //         } else {
                    //             this.$Message.warning(({ content: res.msg, duration: 6, closable: true }));
                    //         }
                    //     })
                    // }
                }
            })

        },
        //勾选列表
        onSelectChange(selection) {
            let myArray = [];
            let arr = []
            selection.map((item, index) => {
                myArray.push(item.id);
                arr.push(item)
            });
            this.delIds = myArray;
            this.printArr = arr
            if (selection.length > 0) {
                this.allCheck = true;
            } else {
                this.allCheck = false;
            }
        },
        //批量删除
        delFaultCodeShowClick() {
            if (this.delIds.length == 0) {
                this.$Message.warning({
                    content: `${this.$t('common.deleteItems')}`,
                    duration: 6,
                    closable: true,
                });
                return;
            } else {
                this.delFaultCodeShowF = true;
            }
        },
        //删除
        delPrrShowH(row) {
            //点击展示提示删除弹窗
            this.delFaultCodeShowF = true;
            this.delIds = [];
            this.delIds.push(row.id);
        },
        deleteOk() {
            this.loading = true;
            let params = {
                standingBookIds: this.delIds + "",
            }
            deleteApi(params).then(res => {
                this.loading = false;
                if (res.code === 200) {
                    this.changeNum();
                    this.$Message.success("删除成功");
                    this.allCheck = false;
                    this.delFaultCodeShowF = false;
                } else {
                    this.$Message.warning(({content: res.msg, duration: 6, closable: true}));
                }
            })
        },
        //下载模板
        exportTemplate() {
            const filName = '备件台账'
            templateApi().then(res => {
                fileDownload(res, filName + '.xlsx')
            })
        },
        //导入
        importExcelShow() {
            this.importExcelState = true;
        },
        importExcelChange(val) {
            this.importExcelState = false;
            if (val === 'success') {
                this.changeNum();
            }
        },
        //导出
        exportTemplateClick() {

            let params = {
                pageNum: this.pageNum,
                pageSize: this.pageSize,
                ids: this.delIds,
            };


            for (let key in this.searchParams) {
                if (this.searchParams[key]) {
                    this.$set(params, key, this.searchParams[key])
                }
            }
            const filName = '备件台账'
            exportApi(params).then(res => {
                fileDownload(res, filName + '.xlsx')
            })
        }
    }
}
</script>

<style scoped lang="scss">
.ivu-input-number {
    width: -webkit-fill-available;
}
</style>



